package com.wang.tool.event;

import java.util.concurrent.Executors;

class Demo{


    public static void main(String[] args) {
        EventBus bus = new EventBus();

//        注册监听器方式
        bus.register(new EventListener<Enent1>() {
            @Override
            public String id() {
                return "listener1";
            }

            @Override
            public Class<Enent1> subscribeEventType() {
                return Enent1.class;
            }

            @Override
            public Object onEvent(Enent1 event) throws Exception {
                //干活
                return null;
            }
        });


//        同步触发
        bus.fire(new Enent1());

//       异步触发
        bus.asyncFire(Executors.newFixedThreadPool(2), new Enent1());


    }


    private static class Enent1{

        private long eventId;

        private String msg;

        public long getEventId() {
            return eventId;
        }

        public void setEventId(long eventId) {
            this.eventId = eventId;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }
    }


}